<?php
header("Content-Type:application/json;charset=utf-8");
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/6/12
 * Time: 17:40
 */
if ($_SERVER["REQUEST_METHOD"]!="POST"){
    $result=array("msg"=>"对不起,不支持get请求","status"=>-1);
    print_r(json_encode($result));
    return;
}
//post请求
if(!(isset($_POST["useName"])&&$_POST["usePwd"])){
    $result=array("msg"=>"用户名或密码不能为空","status"=>-2);
    print_r(json_encode($result));
    return;
}
$useName=$_POST["useName"];
$usePwd=$_POST["usePwd"];

include "DBhelper.php"; //合并DBphp
//sql语句
$sql="SELECT `useID`,`useName`,`useEmaill`,`useTelphone` FROM `use` WHERE useName='".$useName."' AND usePwd='".$usePwd."'";
$resultData=sqlQuery($sql); //object
//6.判断结果
if ($resultData->num_rows>=1){
    //如果登录了,就把当前的登录者的信息保存到session
    session_start();
    $userData=$resultData->fetch_assoc(); //array
    $_SESSION["use"]=$userData;
    $result=array("msg"=>"登录成功","status"=>1,"data"=>$userData);
    print_r(json_encode($result));
}else{
    $result=array("msg"=>"登录失败","status"=>-3);
    print_r(json_encode($result));
}
